#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.common.component.serialization;

import ${package}.common.convert.CustomAuth2SerializeFilter;
import ${package}.common.convert.LongStringFilter;
import ${package}.common.utils.DateUtil;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Description: 序列化配置
 *
 * @author wenxiaopeng
 * @date 2021/01/05 16:56
 *
 * <pre>
 *              ${copyright}
 *      Copyright (c) 2019. All Rights Reserved.
 * </pre>
 */
@Configuration
public class SerializationConfig {

	/**
	 * Description:
	 * <ResponseBody得jsonConverter换成fastJson中的转换器>
	 * @author wupanhua
	 * @date 14:09 2019/8/7
	 * @return org.springframework.boot.autoconfigure.http.HttpMessageConverters
	 **/
	@Bean
	@ConditionalOnMissingBean
	public HttpMessageConverters fastJsonHttpMessageConverters(){
		// 1.需要定义一个Convert转换消息的对象
		FastJsonHttpMessageConverter fastConverter=new FastJsonHttpMessageConverter();
		// 2.添加fastjson的配置信息，比如是否要格式化返回的json数据
		FastJsonConfig fastJsonConfig = new FastJsonConfig();
		fastJsonConfig.setSerializeFilters(new LongStringFilter(), new CustomAuth2SerializeFilter());
		fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.SkipTransientField);
		fastJsonConfig.setDateFormat(DateUtil.DateStyle.ALL.getStyle());
		// 3.在convert中添加配置信息
		fastConverter.setFastJsonConfig(fastJsonConfig);
		return new HttpMessageConverters(fastConverter);
	}
}
